$(function(){
	$(".datepicker").datepicker();
	$("#itemBtn").bind("click",showAddItem);	
});

function showAddItem(){
	window.showModalDialog('contract!input',window);
}

function addLine(data){	
	data.index = gindex++;
	
	var line = template.render("dataLine",data);
	$("#pdtBody").append(line);
}

function removeMe(self){
	$(self).parent().parent().remove();
}

function saveOne(){
	if(!confirm("保存合同?"))return;
	var data = $("#cform").serialize();
    $.post('contract!create',data,function(id){
    	doGet("contract!get?bean.id="+id);
   });
}

function updateOne(){
	if(!confirm("保存合同?"))return;
	var data = $("#cform").serialize();
    $.post('contract!update',data,function(id){
    	doGet("contract!get?bean.id="+id);
   });
}



function editDetail(itemid){
	var assumpsit = $("#ditem_assumpsit_"+itemid).val();
	var custom    = $("#ditem_custom_"+itemid).val();
	var pstr = "detail.id="+itemid+"&detail.assumpsit="+assumpsit+"&detail.custom="+custom;
	$.post('contract!updatedataitem',pstr);
}

function editItem(itemid){
    var vad = $("#validation_"+itemid).val();
    var sto = $("#storage_"+itemid).val();
    var rmk = $("#remark_"+itemid).val();
    var pstr = "item.id="+itemid+"&item.validation="+vad+"&item.storage="+sto+"&item.remark="+rmk;
    $.post('contract!updateitem',pstr);
}

function submitRepo(code,contract,item){
	var url="contract-startsubmit?cid="+contract+"&code="+code+"&item="+item;
	window.showModalDialog(url,window);
}

function showSubmits(contract,code,itemId){
	var url="contract!showsubmits?bean.id="+contract+"&item.owner.code="+code+"&item.id="+itemId;
	$.get(url,function(data){
		var ulc = $("#"+itemId+"_submitation");
		ulc.empty();
		ulc.html(data);
	});
}

function removeItem(self,bid,itemid){

  if(confirm("您确认要删除此项目!")){
	var pstr="bean.id="+bid+"&item.id="+itemid;
	$.post('contract!removeitem',pstr,function(){
		$(self).parent().parent().remove();
	});
  }
}